from configparser import ConfigParser       # 内置库
import os
class Reader:
    def __init__(self,file):
        # 实例化config对象
        self.config = ConfigParser()
        path = os.path.split(os.path.realpath(__file__))[0] + os.sep + file
        self.config.read(path,encoding='utf-8')
    def get_option(self,option):
        """
        :param option: 获取哪一个key
        :return:
        """
        for section in self.config.sections():
            # ["URL",'DATABASE','NAME']
            if self.config.has_option(section,option):
                # 如果某一个section在选项里
                return self.config.get(section,option)      # 直接返回
"""
if __name__ == '__main__':
    print(os.path.split(os.path.realpath(__file__)) )
    print(os.path.split(os.path.realpath(__file__))[0] + os.sep)
"""

